<?php
/**
 * Created by PhpStorm.
 * User: 共赢岛
 * Date: 2023/12/7
 * Time: 17:12
 */

namespace App\Http\Resources;

use App\Admin\Services\CarService;
use App\Models\Car;
use App\Models\CarPackage;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Database\Eloquent\Collection;

class PackageBrandResource extends JsonResource
{
    public function toArray($request)
    {
        $category = $this->carPackageCategory;

        foreach ($category as $key => &$value) {
            $value['cars'] = CarService::carJsonSwitch($value->car_ids);
        }

        return [
            'id' => $this->id,
            'title' => $this->title,
            'pic' => path2url($this->pic),
            'category' => $category
        ];
    }
}